<template>
  <div>
    <div @click="clickTest" class="header">{{ title }}</div>
    <div>{{ list }}</div>
    <div class="test-center">
      <div>
        {{ messageTest }}
      </div>
    </div>
  </div>
</template>

<script lang="ts" setup>
import { defineProps, withDefaults, defineEmits, inject } from 'vue';
import { ElMessageBox } from 'element-plus';

interface IPerson {
  name: string;
  age: number;
}

// scf 方式中 定义 props 设置默认值
const props = withDefaults(
  defineProps<{
    title?: string;
    list?: IPerson[];
  }>(),
  {
    title: '233 title',
    list: () => [],
  }
);

// const emit = defineEmits(['change', 'update'])
const emit = defineEmits<{
  (e: 'iClick', p: IPerson): void;
  (e: 'change'): void;
}>();

const messageTest = inject('messageTest', '这是一个 默认 233');

const clickTest = () => {
  if (props.list.length) {
    emit('iClick', props.list[0]);
    emit('change');

    ElMessageBox({
      title: 'title',
      message: 'message',
    });
  }
};
</script>

<style lang="less" scoped>
.test {
  &-center {
    color: red;
  }
}
</style>
